package pilates.blogmoon.cn.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pilates.blogmoon.cn.api.Result;
import pilates.blogmoon.cn.entity.Category;
import pilates.blogmoon.cn.service.CategoryService;

/**
 * Copyright:
 * Author:
 * Description:
 * Created by 李林山 on 2024/4/15
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @PostMapping("/create")
    public Result createCategory(@RequestBody Category category) {
        categoryService.save(category);
        return Result.OK();
    }

    @PostMapping("/modify")
    public Result modifyCategory(@RequestBody Category category) {
        categoryService.updateById(category);
        return Result.OK();
    }

    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Integer id) {
        categoryService.removeById(id);
        return Result.OK();
    }

    @GetMapping("/list")
    public Result listAll() {
        return Result.OK(categoryService.list());
    }

    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable("id")Integer id){
        return Result.OK(categoryService.getById(id));
    }
}
